package com.zhanglinfeng.eurekaclient.controller;

import com.zhanglinfeng.api.response.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(tags = {"测试服务"})
@RestController
public class TestController {

    @Autowired
    private DiscoveryClient discoveryClient;

    @ApiOperation(value = "查询所有服务", notes = "查询所有服务")
    @GetMapping(value = "/queryServices", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultResponse<List<String>> queryServices() {
        List<String> services = discoveryClient.getServices();
        services.add("端口号 = 2002");

        ResultResponse resultResponse = new ResultResponse();
        resultResponse.setData(services);

        return resultResponse;
    }

    @ApiOperation(value = "上传文件", notes = "上传文件")
    @PostMapping(value = "/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public String handleFileUpload(MultipartFile file) {
        return file.getOriginalFilename();
    }
}
